<pre>
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors','On'); 

$i=0;
$fl=0;
$handle = fopen('all_card.txt','r');
if ($handle)
{
  while(!feof($handle))
  {
    $line = fgets($handle);
    $line1 = explode(" ",$line);
    $param_name = $line1[0];
    if($param_name=='action2_param')
    {
      $fl = 1;
      #$class = '';
      $i++;
    }

    $param_value = trim(substr($line,strlen($param_name)));

    #if (strlen($param_value)!=0)
    {
      #print $param_name.'-'.$param_value;
      #if ($param_name=='name')
      {
        $class[$i][$param_name] = $param_value;
      }
    }
    #print "\n";
  }
}




mysql_connect('localhost', 'tt', 'tt123');
mysql_select_db('tt');

$tt_result = mysql_query('SET NAMES "utf8"');

$tt_result = mysql_query('truncate table tt_cards');
$tt_result = mysql_query('truncate table tt_cards_actions');

#while ($row = mysql_fetch_row($tt_result))
#{
#  var_dump($row);
#}


$i = 0;
foreach ($class as $n)
{
  $i++;
  $sql_type = 'select * from tt_types where tt_types.type = "'.$n['type'].'"';
  $tt_types = mysql_fetch_row(mysql_query($sql_type));
  
  $sql_class = 'select * from tt_classes where tt_classes.class = "'.$n['class'].'"';
  $tt_classes = mysql_fetch_row(mysql_query($sql_class));

  $sql_rare = 'select * from tt_rares where tt_rares.rare = "'.$n['rare'].'"';
  $tt_rares = mysql_fetch_row(mysql_query($sql_rare));

  $sql_time = 'select * from tt_times where tt_times.time = "'.$n['time'].'"';
  $tt_times = mysql_fetch_row(mysql_query($sql_time));


  $sql = 'insert into tt_cards (name,des,nr,type,class,rare,time) values("'.$n['name'].'","'.mysql_real_escape_string($n['Descr']).'",'.$i.','.$tt_types[0].','.$tt_classes[0].','.$tt_rares[0].','.$tt_times[0].')';
  $tt_result = mysql_query($sql);

  $id = mysql_insert_id();
  if($n['action'] != '')
  {
    $sql_action = 'select * from tt_actions where tt_actions.action = "'.$n['action'].'"';
    $tt_actions = mysql_fetch_row(mysql_query($sql_action));

    $sql = 'insert into tt_cards_actions (card,nr,action,param) values('.$id.',1,'.$tt_actions[0].',"'.$n['action_param'].'")';
    $tt_result = mysql_query($sql);
  }
  if($n['action2'] != '')
  {
    $sql_action = 'select * from tt_actions where tt_actions.action = "'.$n['action2'].'"';
    $tt_actions = mysql_fetch_row(mysql_query($sql_action));

    $sql = 'insert into tt_cards_actions (card,nr,action,param) values('.$id.',2,'.$tt_actions[0].',"'.$n['action2_param'].'")';
    $tt_result = mysql_query($sql);
  }
  if($n['action3'] != '')
  {
    $sql_action = 'select * from tt_actions where tt_actions.action = "'.$n['action3'].'"';
    $tt_actions = mysql_fetch_row(mysql_query($sql_action));

    $sql = 'insert into tt_cards_actions (card,nr,action,param) values('.$id.',3,'.$tt_actions[0].',"'.$n['action3_param'].'")';
    $tt_result = mysql_query($sql);
  }


}

?>
</pre>